# coding=UTF-8

from PIL import Image


def init_img_array(image_path):
    img = Image.open(image_path)
    return img


def clear_r_g_b(r, g, b, sharpness):
    if int(r) > sharpness or int(g) > sharpness or int(b) > sharpness:
        r = 255
        g = 255
        b = 255
    else:
        r = 0
        g = 0
        b = 0
    return r, g, b


class ImageHandler:
    def __init__(self):
        pass

    @staticmethod
    def get_img_horizontal_array(img, sharpness):
        img_horizontal_array = []
        length = img.size[0]
        width = img.size[1]
        for j in range(0, width):
            horizontal_array = []
            for i in range(0, length):
                r, g, b = img.getpixel((i, j))
                horizontal_array.append(str(clear_r_g_b(r, g, b, sharpness)))
            img_horizontal_array.append(horizontal_array)
        return img_horizontal_array

    @staticmethod
    def get_img_vertical_array(img, sharpness):
        img_vertical_array = []
        length = img.size[0]
        width = img.size[1]
        for i in range(0, length):
            vertical_array = []
            for j in range(0, width):
                r, g, b = img.getpixel((i, j))
                vertical_array .append(str(clear_r_g_b(r, g, b, sharpness)))
            img_vertical_array.append(vertical_array)
        return img_vertical_array
